/*
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see http://www.gnu.org/licenses/. 
 *
 *  Authors:
 *  	Albert Marieges Garcia
 *  	Álex Pardo Fernández
 *  	Enric Mayas Márquez
 *  	Juan Carlos Calvo Tejedor
 *  	Marc Gironés Dezsényi
 *  
 *  Contact:
 *  	bcn.tours.android@gmail.com
 *  Webpage:
 *  	bcntours.co.cc
 *
 */
package com.BCNTours.Vista;

import java.util.List;

import com.BCNTours.R;
import com.BCNTours.Vista.RowData;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class CustomAdapter extends ArrayAdapter<RowData> {
	/*Attribution*/
	private LayoutInflater mInflater;
	
	/**
	 * Constructor of the class
	 * 
	 * @param context
	 * @param mInflater
	 * @param resource
	 * @param textViewResourceId
	 * @param objects
	 */
    public CustomAdapter(Context context, LayoutInflater mInflater ,int resource, int textViewResourceId, List<RowData> objects) {
            super(context, resource, textViewResourceId, objects);
    		this.mInflater = mInflater;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
            ViewHolder holder = null;

            TextView title = null;
            @SuppressWarnings("unused")
			TextView detail = null;
            ImageView i11=null;
            
            RowData rowData= getItem(position);

            if(null == convertView){
                    convertView = mInflater.inflate(R.layout.favorites_list, null);
                    holder = new ViewHolder(convertView);
                    convertView.setTag(holder);                   
            }
            holder = (ViewHolder) convertView.getTag();    
            	                	
            title = holder.gettitle();     
            title.setText(rowData.mTitle);
            
               
	    	Log.i("picture", "picture");
	        i11=holder.getImage();
	        i11.setImageResource(rowData.imgId);

            return convertView;
    }
    
    private class ViewHolder {      
        private View mRow;
        private TextView title = null;
        @SuppressWarnings("unused")
		private TextView detail = null;
        private ImageView i11=null;            
        
            public ViewHolder(View row) {
            mRow = row;
            }

            public TextView gettitle() {
                    if(null == title){
                            title = (TextView) mRow.findViewById(R.id.title);
                    }
                    return title;
            }
                        
            
            public ImageView getImage() {
                if(null == i11){
                    i11 = (ImageView) mRow.findViewById(R.id.img);                        
            }
            return i11;
    }
         
}
}
